from fastapi import APIRouter, Cookie, Path, status, HTTPException

from typing import Annotated, Optional

from src.weather_service.services.region_weather import Region_weather_service

region_weather_router = APIRouter(tags=["region_weather"])


@region_weather_router.post(
    "/region/{regionId}/weather/{weatherld}",
    status_code=status.HTTP_200_OK
)
async def change_region_for_weather(
    regionId: Annotated[Optional[int], Path(alias="regionId")],
    weatherId: Annotated[int, Path(alias="weatherld")],
    id: Annotated[int | None, Cookie()] = None
):
    if regionId is None or regionId <= 0:
        raise HTTPException(status_code=400, detail="bad data")
    if weatherId is None or weatherId <= 0:
        raise HTTPException(status_code=400, detail="bad data")
    return await Region_weather_service().change_region_id(
        regionId=regionId,
        weatherId=weatherId,
        user_id=id
    )


@region_weather_router.delete(
    "/region/{regionId}/weather/{weatherld}",
    status_code=status.HTTP_200_OK
)
async def delete_weather_for_region(
    regionId: Annotated[Optional[int], Path(alias="regionId")],
    weatherId: Annotated[int, Path(alias="weatherld")],
    id: Annotated[int | None, Cookie()] = None
):
    if regionId is None or regionId <= 0:
        raise HTTPException(status_code=400, detail="bad data")
    if weatherId is None or weatherId <= 0:
        raise HTTPException(status_code=400, detail="bad data")
    return await Region_weather_service().delete_weather_for_region(
        regionId=regionId,
        weatherId=weatherId,
        user_id=id
    )
